package info.javafans.cdn.web.action;

import info.javafans.cdn.dao.MemberDao;
import info.javafans.cdn.domain.Member;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

public class LoginAction extends Action {

	protected static Logger logger = Logger.getLogger(Action.class);
	@Override
	public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		
		ShowIndexAction.prepareDate(request, response);
		
		Member member = MemberDao.doLogin(username, password);
		if (member != null) {
			HttpSession session = request.getSession();
			session.setAttribute("member", member);
			return "success";
		}
		else {
			request.setAttribute("error", "用户名或密码错误!");
			return "success";
		}
	}

}
